<template>
  <div class="hello">
    <div>===================这里是组件1 start==================</div>
    <div>组件2状态机 key2===={{ key2 }}</div>
    <div>组件2状态机 key3==={{ key3 }}</div>
    <button @click="handleAdd">更新key1</button>
    <div>===================这里是组件1 end==================</div>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },
  data() {
    return {
      key2: [],
      key3: {},
    };
  },
  created() {},
  mounted() {
    this.key2 = this.$Store.store.key2;
    this.key3 = this.$Store.store.key3;
    this.$Store.subscribe("key2", (newValue) => {
      this.key2 = newValue;
      // console.log(`这里是组件1,key2新值=`, JSON.stringify(newValue));
    });
    this.$Store.subscribe("key3", (newValue) => {
      this.key3 = newValue;
      console.log(`这里是组件1,key3新值=`, newValue);
    });
  },
  methods: {
    handleAdd() {
      this.$Store.store.key1 += 1;
      // store.key1.push(`${Date.now()}`);
      console.log("===========组件1 handleAdd", this.$Store);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped></style>
